2  Git in R

2.1 Setting up Git

Quick settings :

  • Have a Github account
  • Open an R project.
  • Use package usethis :
library(usethis) ## or library(devtools)
use_git_config(user.name = "Jane Doe", user.email = "jane@example.com")

# check by running a git situation-report: 
#   - your user.name and user.email should appear in global Git config 
git_sitrep()

use_git() # Initialize git
use_github(private = TRUE) # Create github repo, private or not

https://happygitwithr.com/ This is the best guide for Git in R currently.

2.1.1 Create a PAT

How to create a Personal Access Token (PAT).

library(gitcreds)
gitcreds_get()
gitcreds_set()

2.2 Using Git with multiple local accounts

The idea behind using Git with multiple accounts including multiple Github account is to be able to separate your personal from your office work.

Happy Git with R recommends HTTPS instead of SSH. Happy Git with R

There’s plenty of guides that explain how to do it:

Use usethis::git_sitrep() to troubleshoot things.

However they fail to mention one thing:

The current git (local) protocol used is determined by the remote link of the current git repo.

Use git remote -v

As such, you can easily have a main account with PAT, and have a local git folder with SSH for your other account. You just need to choose the correct protocol.